package com.woniu.postbar.controller;

import com.woniu.common.entity.Result;
import com.woniu.postbar.entity.vo.UserPostVO;
import com.woniu.postbar.pojo.UserPost;
import com.woniu.postbar.service.IUserPostService;
import com.woniu.postbar.service.impl.UserPostServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wu
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/userPost")
@Api(tags = "社区发布帖子模块")
public class UserPostController {

    @Autowired
    private IUserPostService userPostService;


    @GetMapping("/list")
    @ApiOperation("根据标题模糊查询帖子")
    public Result<List<UserPostVO>> listAnnouncement(String title){
        List<UserPostVO> user = userPostService.listAnnouncement(title);
         return Result.ok(user);
    }

    @PostMapping("/addPost")
    @ApiOperation("用户添加帖子")
    public Result addPost(@RequestBody UserPost userPost){
        boolean addUserPost = userPostService.addPost(userPost);
        return Result.ok(addUserPost);
    }

    @GetMapping("/listUserTimeCategorize")
    @ApiOperation("根据发布时间来排序展示")
    public Result userTimeCategorize(){
        List<UserPost> userPostList = userPostService.userTimeCategorize();
        return Result.ok(userPostList);
    }

    @GetMapping("/listUserNumCategorize")
    @ApiOperation("根据评论数来排序展示")
    public Result userCommentCategorize(){
        List<UserPost> userPostList = userPostService.userCommentCategorize();
        return Result.ok(userPostList);
    }
}
